from errors import Missing

_clients = []


def get_all_clients_json() -> list[dict]:
    return _clients


def get_client_json(client_id: int) -> dict:
    for client in _clients:
        if client["id"] == client_id:
            return client

    raise Missing(msg=f"Client with id={client_id} does not exist")


def create_client_json(
    name: str, surname: str, credit_card: str, car_number: str
) -> dict:
    client = {
        "id": len(_clients) + 100,
        "name": name,
        "surname": surname,
        "credit_card": credit_card,
        "car_number": car_number,
    }

    _clients.append(client)
    return client
